package com.edu.glutdataconvertserver.servicce.service;

import com.edu.glutdataconvertcommon.domain.EduYhJs;
import com.edu.glutdataconvertcommon.vo.BaseListVO;
import com.edu.glutdataconvertserver.common.Constants;
import com.edu.glutdataconvertserver.common.RedisService;
import com.edu.glutdataconvertserver.mapper.auto.EduYhJsMapper;
import com.edu.glutdataconvertserver.servicce.CommonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;

/**
 * @author gtl
 * @version 1.0
 * @date 2020/10/19  10:45
 */
@Service
public class CommonServiceImpl implements CommonService {

    @Resource
    private EduYhJsMapper eduYhJsMapper;

    @Resource
    private RedisService redisService;

    @Override
    public void addYhJsMulTran(BaseListVO vo) {
        EduYhJs eduYhJs = new EduYhJs();
        eduYhJs.setScbj("1");
        eduYhJs.setEduJsJsdm(vo.getJsdm());
        for (String s : vo.getList()) {
            eduYhJs.setEduYhBh(s);
            int count = eduYhJsMapper.selectCount(eduYhJs);
            if (count > 0) {
                continue;
            }
            eduYhJs.setCjr("1");
            eduYhJs.setCjsj(new Date());
            eduYhJs.setGxr("1");
            eduYhJs.setGxsj(new Date());
            eduYhJsMapper.insertSelective(eduYhJs);
//            this.delRedis(s);
        }
    }

    private void delRedis(String bh) {
        Set<Serializable> keys = redisService.keys(Constants.USER_REDIS_PRE + bh + ":*");
        if (keys.size() > 0) {
            for (Serializable key : keys) {
                redisService.remove(key.toString());
            }
        }
    }
}
